//
//  vdRTTarget.h
//  Void Dead
//
//  Created by Sidney Just on 23.03.10.
//
//  Copyright © 2009 by Sidney Just
//  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
//  documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
//  and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
//  PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
//  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#import <Foundation/Foundation.h>

#import "vdHeader.h"
#import "vdKernel.h"
#import "vdRenderer.h"
#import "vdTexNode.h"
#import "vdNode.h"

/**
 * \brief Class to render nodes to a texture
 *
 * This class gives you the possibility to render a vdNode into a vdTexNode.
 * <br>Unlike the vdRenderTarget struct, this class can also be used under OpenGL ES 1.1 to create some nice effects.
 **/
@interface vdRTTarget : NSObject {
	// \cond
	GLuint framebuffer;
	GLint	lastFramebuffer;
	GLuint texHandle;
	
	vdTexNode *texture;
	
	BOOL bound;
	// \endcond
}

/**
 * Pointer to the texture where the scene gets rendered into.
 @remark Before you render something into the texture, this texture is just a black texture.
 **/
@property (readonly) vdTexNode *texture;

/**
 * Binds the framebuffer, all rendering after this call will be draw into the texture.
 @remark Don't forget to unbind the framebuffer ;)
 **/
- (void)bind;

/**
 * This will unbind the framebuffer and bind the framebuffer bound before the bind call.
 * <br>The vdRenderer will be flushed automatically, so you don't need to do this.
 **/
- (void)unbind;

/**
 * Clears the framebuffer with the given color
 @param color The color you want to clear the framebuffer with.
 **/
- (void)clear:(vdColor *)color;

/**
 * Renders the node into the texture.
 @param node The node you want to render into the texture
 @param offset The offset of the node on the x and y axis.
 @return If you don't have bound the framebuffer, this function will return NO, otherwise YES
 @remark You may call this function only between vdEngineFrameDidBegin and vdEngineFrameWillEnd, otherwise you might get unexpected results.
 **/
- (BOOL)renderNode:(vdNode *)node withOffset:(CGPoint)offset;

/**
 * Creates a new vdRTTarget with the given size
 @param rect Size of the new vdRTTarget (size - origin)
 @return Pointer to a new vdRTTarget instance or NULL
 @remark The size must be power of two!
 **/
- (id)initWithSize:(CGRect)rect;

/**
 * Creates a new vdRTTarget with 512x512 (iPhone) or 1024x1024 (iPad) pixels
 @return Pointer to a new vdRTTarget instance or NULL
 **/
- (id)init;

@end
